import { searchFormProps } from "@/components/SearchForm/interface";

/**
 * @param {Array} dataGrid 搜索的表格
 * @param {Ref} proTableBox 表格的ref
 * @param {string} queryField 搜索的字段(多个以逗号分隔)
 * @param {string} placeholder 提示站位符
 * @param {string} type input框类型
 * @description 自定义搜索条件
 */
export const useSearchForm = () => {
  const searchForm = reactive<searchFormProps>({
    form: {
      userId: ""
    },
    options: [
      {
        type: "input",
        label: "",
        prop: "text",
        children: [],
        hide: false,
        defaultValue: ""
      },
      {
        type: "select",
        label: "",
        prop: "userId",
        children: [],
        hide: false,
        defaultValue: 6
      },
      {
        type: "select",
        label: "收益",
        prop: "earnings",
        children: [
          {
            text: "正收益",
            value: 1
          },
          {
            text: "负收益",
            value: 0
          }
        ],
        hide: false,
        defaultValue: ""
      }
    ]
  });

  /**
   * @description: 获取所有用户
   * @return {*}
   */
  const getAllUser = async () => {
    const data: any = await userFindAllUser();

    for (let item of searchForm.options) {
      if (item.prop === "userId") {
        item.children = data.map(item => {
          return {
            text: item.userName,
            value: item.id
          };
        });
      }
    }
  };

  return {
    searchForm,
    getAllUser
  };
};
